| Conditions | 1 |
| Paths | 1 |
| Total Lines | 106 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var WPInv_Admin; |
||
| 3 | jQuery( document ).ready( function ( $ ) { |
||
| 4 | |||
| 5 | var WPInv_Recurring = { |
||
| 6 | init: function () { |
||
| 7 | |||
| 8 | //Recurring select field conditionals |
||
| 9 | this.edit_expiration(); |
||
| 10 | this.edit_product_id(); |
||
| 11 | this.edit_profile_id(); |
||
| 12 | this.edit_txn_id(); |
||
| 13 | this.delete(); |
||
| 14 | |||
| 15 | }, |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Edit Subscription Text Input |
||
| 19 | */ |
||
| 20 | edit_subscription_input: function (link, input) { |
||
| 21 | |||
| 22 | //User clicks edit |
||
| 23 | if (link.text() === WPInv_Admin.action_edit) { |
||
|
|
|||
| 24 | //Preserve current value |
||
| 25 | link.data('current-value', input.val()); |
||
| 26 | //Update text to 'cancel' |
||
| 27 | link.text(WPInv_Admin.action_cancel); |
||
| 28 | } else { |
||
| 29 | //User clicked cancel, return previous value |
||
| 30 | input.val(link.data('current-value')); |
||
| 31 | //Update link text back to 'edit' |
||
| 32 | link.text(WPInv_Admin.action_edit); |
||
| 33 | } |
||
| 34 | |||
| 35 | }, |
||
| 36 | |||
| 37 | edit_expiration: function() { |
||
| 38 | |||
| 39 | $('.wpinv-edit-sub-expiration').on('click', function(e) { |
||
| 40 | e.preventDefault(); |
||
| 41 | |||
| 42 | var link = $(this); |
||
| 43 | var exp_input = $('input.wpinv-sub-expiration'); |
||
| 44 | WPInv_Recurring.edit_subscription_input(link, exp_input); |
||
| 45 | |||
| 46 | $('.wpinv-sub-expiration').toggle(); |
||
| 47 | $('#wpinv-sub-expiration-update-notice').slideToggle(); |
||
| 48 | }); |
||
| 49 | |||
| 50 | }, |
||
| 51 | |||
| 52 | edit_profile_id: function() { |
||
| 53 | |||
| 54 | $('.wpinv-edit-sub-profile-id').on('click', function(e) { |
||
| 55 | e.preventDefault(); |
||
| 56 | |||
| 57 | var link = $(this); |
||
| 58 | var profile_input = $('input.wpinv-sub-profile-id'); |
||
| 59 | WPInv_Recurring.edit_subscription_input(link, profile_input); |
||
| 60 | |||
| 61 | $('.wpinv-sub-profile-id').toggle(); |
||
| 62 | $('#wpinv-sub-profile-id-update-notice').slideToggle(); |
||
| 63 | }); |
||
| 64 | |||
| 65 | }, |
||
| 66 | |||
| 67 | edit_product_id: function() { |
||
| 68 | |||
| 69 | $('.wpinv-sub-product-id').on('change', function(e) { |
||
| 70 | e.preventDefault(); |
||
| 71 | |||
| 72 | $('#wpinv-sub-product-update-notice').slideDown(); |
||
| 73 | }); |
||
| 74 | |||
| 75 | }, |
||
| 76 | |||
| 77 | edit_txn_id: function() { |
||
| 78 | |||
| 79 | $('.wpinv-edit-sub-transaction-id').on('click', function(e) { |
||
| 80 | e.preventDefault(); |
||
| 81 | |||
| 82 | var link = $(this); |
||
| 83 | var txn_input = $('input.wpinv-sub-transaction-id'); |
||
| 84 | WPInv_Recurring.edit_subscription_input(link, txn_input); |
||
| 85 | |||
| 86 | $('.wpinv-sub-transaction-id').toggle(); |
||
| 87 | }); |
||
| 88 | |||
| 89 | }, |
||
| 90 | |||
| 91 | delete: function() { |
||
| 92 | |||
| 93 | $('.wpinv-delete-subscription').on('click', function(e) { |
||
| 94 | |||
| 95 | if( confirm( WPInv_Admin.delete_subscription ) ) { |
||
| 96 | return true; |
||
| 97 | } |
||
| 98 | |||
| 99 | return false; |
||
| 100 | }); |
||
| 101 | |||
| 102 | } |
||
| 103 | |||
| 104 | }; |
||
| 105 | |||
| 106 | WPInv_Recurring.init(); |
||
| 107 | |||
| 108 | } ); |
||
| 109 |